"""Controller for current groups."""

from mnemoply.controllers.lookup import TableLookupDataSource, LookupController
from mnemoply.controllers.Group import GroupController
from turbogears import identity
from mnemoply.model.auth import AuthUserOffice, AuthUserFaculty, AuthUserOrg

class CurrentGroupDataSource(TableLookupDataSource):
    """
        Provides `group_lookup` with filtration by `is_open`.
    """

    def __init__(self):
        TableLookupDataSource.__init__(self, 'group_lookup')

    def _buildWhereChunks(self, request):
        chunks = TableLookupDataSource._buildWhereChunks(self, request)
        chunks.append("(is_open)")  # see schema-addon/views.sql
        chunks.append(self.buildChunksOr("office", AuthUserOffice))
        chunks.append(self.buildChunksOr("faculty", AuthUserFaculty))
        chunks.append(self.buildChunksOr("organization", AuthUserOrg))
        return chunks
 
class CurrentGroupController(LookupController):
    """Controller for current groups."""

    def __init__(self):
#        GroupController.__init__(self, data_source=CurrentGroupDataSource())
        self.title = _("Current groups")

#exposed = CurrentGroupController()
